package io.renren.modules.generator.controller;

import io.renren.common.utils.R;
import io.renren.modules.generator.service.SequenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * User: 齐丹枫
 * Date: 2019/1/17
 * Time: 9:36
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@RestController
@RequestMapping("/sequenceController")
public class SequenceController {

    @Autowired
    private SequenceService sequenceService;

    @GetMapping("/getSequenceCurrentValueBySequenceName")
    public R getSequenceCurrentValueBySequenceName(@RequestParam String name,@RequestParam int length){
        String currentValue = sequenceService.getCurrentValue(name, length);
        return R.ok().put("data",currentValue);
    }

    @GetMapping("/getSequenceNextValueBySequenceName")
    public R getSequenceNextValueBySequenceName(@RequestParam String name,@RequestParam int length){
        String nextValue = sequenceService.getNextValue(name, length);
        return R.ok().put("data",nextValue);
    }

    @GetMapping("/setSequenceCurrentValueBySequenceName")
    public R setSequenceCurrentValueBySequenceName(@RequestParam String name,@RequestParam String value){
        sequenceService.setCurrentValue(name,value);
        return R.ok();
    }



}
